package org.NooLab.openNLP.utilities;

import java.io.*;
import org.w3c.dom.*;
import org.xml.sax.InputSource;
import org.apache.xpath.NodeSet;
import org.apache.xpath.domapi.XPathEvaluatorImpl;

import javax.xml.xpath.*;

// import org.apache.xpath.domapi.XPathEvaluatorImpl;



public class HtmlTableXPathEvaluator {

	public static void evaluateDocument(File xmlDocument) {

		String expression;
		
		XPathFactory factory;
		XPath xPath ;
		XPathExpression xPathExpression ;
		
		Element show ;
		
		try {

			factory = XPathFactory.newInstance();
			xPath = factory.newXPath();
			InputSource inputSource = new InputSource( new FileInputStream( xmlDocument));
			
			xPathExpression = xPath.compile("/table[@id='main-content']");

			expression = "/table[@id='main-content']";
			inputSource = new InputSource(new FileInputStream(xmlDocument));
			NodeList shows = (NodeList) xPath.evaluate(expression, inputSource, XPathConstants.NODESET);

			for (int i = 0; i < shows.getLength(); i++) {
				
				show = (Element) shows.item(i);
				System.out.println("The value of show.getTagName(): " + show.getTagName());
				System.out.println("The value of show.getTextContent(): " + show.getTextContent());
			}
		} catch (IOException e) {
		} catch (XPathExpressionException e) {
		}
	}

	public static void main(String[] argv) {

		File xmlDocument = new File("C:/Temp/HTMLTable.txt");
		evaluateDocument(xmlDocument);
		
	}
}
